// import com.alibaba.druid.sql.ast.SQLExpr;
// import com.alibaba.druid.sql.ast.SQLName;
// import com.alibaba.druid.sql.ast.SQLReplaceable;
// import com.alibaba.druid.sql.ast.SQLStatementImpl;
// import com.alibaba.druid.sql.visitor.SQLASTVisitor;

#include "SQLShowViewsStatement.h"
#include "../../visitor/SQLASTVisitor.h"
#include "../../../utils/listTran.h"
#include "../SQLName.h"

SQLName_ptr SQLShowViewsStatement::getDatabase()
{
  return database;
}

void SQLShowViewsStatement::setDatabase(SQLName_ptr x)
{
  if (x != nullptr)
  {
    x->setParent(SharedObject(SQLShowViewsStatement));
  }

  this->database = x;
}

SQLExpr_ptr SQLShowViewsStatement::getLike()
{
  return like;
}

void SQLShowViewsStatement::setLike(SQLExpr_ptr x)
{
  if (x != nullptr)
  {
    x->setParent(SharedObject(SQLShowViewsStatement));
  }

  this->like = x;
}

// @Override
void SQLShowViewsStatement::accept0(SQLASTVisitor_ptr visitor)
{
  if (visitor->visit(SharedObject(SQLShowViewsStatement)))
  {
    acceptChild(visitor, database);
    acceptChild(visitor, like);
  }
}

// @Override
BOOL_ptr SQLShowViewsStatement::replace(SQLExpr_ptr expr, SQLExpr_ptr target)
{
  if (database == expr)
  {
    setDatabase(std::dynamic_pointer_cast<SQLName>(target));
    return BOOL::TRUE;
  }

  if (like == expr)
  {
    setLike(target);
    return BOOL::TRUE;
  }

  return BOOL::FALSE;
}
